#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_threephot.info <<'%EOF%'
   cc_rsp_threephot
   ----------------
   Molecule:         HF in C2v
   Wave Function:    CCS, CC2, CCSD / 6-31G**
   Test Purpose:     Threephoton transition moments
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_threephot.mol <<'%EOF%'
BASIS
6-31G**
Hydrogen flourid
small test basis
    2    2  Y  X      1.00D-15
        9.0   1    
F     0.0000000000000000  0.0000000000000000 1.76320000000000000      
        1.0   1
H     0.0000000000000000  0.0000000000000000 0.00000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_threephot.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
**WAVE FUNCTIONS
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CCS
.CC2
.CCSD
.NSYM
 4
.THRENR
 1.0d-8
.THRLEQ
 1.0d-8
.PRINT
   2
*CCEXCI
.NCCEXCI
  0 0 0 1
.THREXC
 1.0d-8
*CCTM
.SELSTA
 4 1 0.0 0.2
.OPERATOR
YDIPLEN XDIPLEN ZDIPLEN YDIPLEN XDIPLEN ZDIPLEN
*CCLRSD
.DIPOLE
**END OF DALTON INPUT
%EOF%
#######################################################################


#######################################################################

#######################################################################
# CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_threephot.check
cat >>cc_rsp_threephot.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Final * HF energy:" $log | $GREP "\-100.008919(8|9)." | wc -l`
CRIT2=`$GREP "Total MP2   energy:                  \-100.193662(5|6)." $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy:                  \-100.1977909." $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[1]=5
ERROR[1]="ENERGIES NOT CORRECT"

# CCS threephoton transition moment
CRIT1=`$GREP "M\^ABC_of\(\-w1,\-w2\): *( |\-)7\.5383.." $log |
       $GREP "M\^DEF_fo\(w1,w2\): *( |\-)3\.5001(0|1)." | wc -l`
CRIT2=`$GREP "M\^DEF_of\(\-w1,\-w2\): *( |\-)7\.5383.." $log |
       $GREP "M\^ABC_fo\(w1,w2\): *( |\-)3\.5001(0|1)." $log | wc -l`
CRIT3=`$GREP "M\^ABC_of\(\-w1,\-w2\) x M\^DEF_fo\(w1,w2\)   = * 26\.385(0|1).." $log | wc -l`
CRIT4=`$GREP "M\^DEF_of\(\-w1,\-w2\) x M\^ABC_fo\(w1,w2\)\]\* = * 26\.385(0|1).." $log | wc -l`
CRIT5=`$GREP "CCS  S\^of_ABC,DEF" $log | $GREP "26\.385(0|1)." | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[2]=5
ERROR[2]="CCS THREEPHOTON TRANSITION MOMENTS OR STRENGTH NOT CORRECT"

# CC2 threephoton transition moment
CRIT1=`$GREP "M\^ABC_of\(\-w1,\-w2\): *( |\-)5\.05244." $log |
       $GREP "M\^DEF_fo\(w1,w2\): * ( |\-)2\.4896(7|8)." | wc -l`
CRIT2=`$GREP "M\^DEF_of\(\-w1,\-w2\): *( |\-)5\.05244." $log |
       $GREP "M\^ABC_fo\(w1,w2\): * ( |\-)2\.4896(7|8)." $log | wc -l`
CRIT3=`$GREP "M\^ABC_of\(\-w1,\-w2\) x M\^DEF_fo\(w1,w2\)   = * 12\.5789(7|8)." $log | wc -l`
CRIT4=`$GREP "M\^DEF_of\(\-w1,\-w2\) x M\^ABC_fo\(w1,w2\)\]\* = * 12\.5789(7|8)." $log | wc -l`
CRIT5=`$GREP "CC2  S\^of_ABC,DEF" $log | $GREP "12\.5789(7|8)." | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[3]=5
ERROR[3]="CC2 THREEPHOTON TRANSITION MOMENTS OR STRENGTH NOT CORRECT"

# CCSD threephoton transition moment
CRIT1=`$GREP "M\^ABC_of\(\-w1,\-w2\): *( |\-)7\.590(29|30)." $log |
       $GREP "M\^DEF_fo\(w1,w2\): * ( |\-)1\.6687(3|4).." | wc -l`
CRIT2=`$GREP "M\^DEF_of\(\-w1,\-w2\): *( |\-)7\.590(29|30)." $log |
       $GREP "M\^ABC_fo\(w1,w2\): * ( |\-)1\.6687(3|4).." $log | wc -l`
CRIT3=`$GREP "M\^ABC_of\(\-w1,\-w2\) x M\^DEF_fo\(w1,w2\)   = * 12\.6662.." $log | wc -l`
CRIT4=`$GREP "M\^DEF_of\(\-w1,\-w2\) x M\^ABC_fo\(w1,w2\)\]\* = * 12\.6662.." $log | wc -l`
CRIT5=`$GREP "CCSD S\^of_ABC,DEF" $log | $GREP "12\.6662.." | wc -l`
TEST[4]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[4]=5
ERROR[4]="CCSD THREEPHOTON TRANSITION MOMENTS OR STRENGTH NOT CORRECT"
#
# CCS/CC2/CCSD excitation energies:
CRIT1=`$GREP "\^1A2[ \|]* 1[ \|]*  1\.455144.  \|      39\.596..  \|    319367\....  \| 100\.00" $log | wc -l`
CRIT2=`$GREP "\^1A2[ \|]* 1[ \|]*  1\.518329.  \|      41\.315..  \|    333234\....  \|  99\.13" $log | wc -l`
CRIT3=`$GREP "\^1A2[ \|]* 1[ \|]*  1\.328216.  \|      36\.142..  \|    291509\....  \|   ( |0)\.35" $log | wc -l`
TEST[5]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[5]=3
ERROR[5]="CC EXCITATION ENERGIES NOT CORRECT"

# CCS/CC2/CCSD one-photon transition moments:
CRIT1=`$GREP "\^1A2[ \|]* 1[ \|]* ( |0)\.0000000 [ \|]* ( |0).0000000 [ \|]* \- " $log | wc -l`
TEST[6]=`expr $CRIT1`
CTRL[6]=3
ERROR[6]="CC ONEPHOTON TRANSITION MOMENTS NOT CORRECT"


PASSED=1
for i in 1 2 3 4 5 6
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi                
%EOF%
#######################################################################
